#include "whaletweetentry.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QTextBrowser>

WhaleTweetEntry::WhaleTweetEntry( QVariantMap data, QWidget * parent )
    : WhaleAbstractEntry( data, parent ) {

    QVariantMap user = data[ "user" ].toMap();
    QString userId = user[ "id" ].toString();

    this->mName = user[ "screen_name" ].toString();
    this->mText = data[ "text" ].toString();
    this->mAvatarUrl = user[ "profile_image_url" ].toString();

    QHBoxLayout * layout = new QHBoxLayout();
    layout->setMargin( 0 );
    layout->setSpacing( 0 );
    this->setLayout( layout );

    this->mAvatarLabel = new WhaleAvatar( this->mAvatarUrl, userId );

    QTextBrowser * browser = new QTextBrowser();
    browser->setOpenLinks( false );
    browser->setOpenExternalLinks( true );
    browser->setText( "<b>" + this->mName + "</b>: " + this->mText );
    browser->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    browser->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
    browser->setFixedHeight( 100 );

    // this->connect( browser, SIGNAL( anchorClicked( QUrl ) ), this, SLOT( OpenWebPage( QUrl ) ) );

    this->layout()->addWidget( this->mAvatarLabel );
    this->layout()->addWidget( browser );

    this->setSizePolicy( QSizePolicy( QSizePolicy::Ignored, QSizePolicy::Fixed ) );

    this->setObjectName( "whaletweetwidget" );
}
